﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace FDEE.Model
{

    class CPTM3S : CPTMBase
    {
        //double spaceAlignW, spaceAlignL;       
        Dictionary<double, List<int>> dic = new Dictionary<double, List<int>>();
        Dictionary<double, List<int>> addDic = new Dictionary<double, List<int>>();

        internal CPTM3S(string typeName, string pierNumber, eColumnType ct, eSubType st,
            int ww, int ll, int hh, int rr, double up, double low,
            eDB mainDB, string listCString = "",string listAddCString = "") 
            : base(typeName, pierNumber, ct,st, ww, ll, hh, rr, up, low, mainDB)
        {
            listCString = "{(4,6,10,11,15,17)|220};{(5,16)|300};{(7,9,12,14)|135};{(0,21)|200};{(1,2,3,4,5,6,7,8)|3001}";
            listAddCString = "{(5,16)|300};{(7,9,12,14)|135};{(1,2,4,6,8)|185}";
            //listCString = "{(4,6,8,11,13,15)|135};{(3,5,9,10,14,16)|220}";
            //listAddCString = "{(4,6,8,11,13,15)|135}";
            List<string> listC = listCString.Split(';').ToList();
            List<string> listAddC = listAddCString.Split(';').ToList();
            Dictionary<double, List<int>> dicV = new Dictionary<double, List<int>>();
          
            foreach (var item in listC)
            {
                string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                double vk = double.Parse(values[1]);
                string[] vs = values[0].Split(',');
                List<int> v = new List<int>();
                foreach(var vl in vs)
                {
                    v.Add(int.Parse(vl));
                }
                if(!dicV.Keys.Contains(vk))
                    dicV.Add(vk, v);
                //dic= dicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                dic = dicV;
            }
            Dictionary<double, List<int>> adddicV = new Dictionary<double, List<int>>();
            foreach (var item in listAddC)
            {
                string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                double vk = double.Parse(values[1]);
                string[] vs = values[0].Split(',');
                List<int> v = new List<int>();
                foreach (var vl in vs)
                {
                    v.Add(int.Parse(vl));
                }
                if (!adddicV.Keys.Contains(vk))
                    adddicV.Add(vk, v);
                //addDic = adddicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                addDic = adddicV;
            }
        }

        public override void SetRebarDistribute()
        {
            double d1, d2;
            switch (SubType)
            {                
                case eSubType.C:
                    d1 = (Length - Radius * 2) / 19;
                    d2 = (Width - Radius * 2) / 7;
                    d1 = 80;
                    d2 = 110;
                    //spaceAlignW = d2;
                    //spaceAlignL = d1;
                    //A截面参数
                    MainLBarDistribute = new RebarTendonDistribute(32, d1, 19);
                    AddLBarDistribute = new RebarTendonDistribute();
                    AddLBarDistribute.Location = MainLBarDistribute.Delete(new List<int>() { 1, 3,5,7,9,10,12,14,16,18 });
                    MainWBarDistribute = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistribute = new RebarTendonDistribute();
                    AddWBarDistribute.Location = MainWBarDistribute.Delete(new List<int>() {2,4, 6});
                    //B截面参数
                    MainLBarDistributeB = new RebarTendonDistribute(32, d1, 19);
                    AddLBarDistributeB = new RebarTendonDistribute();
                    MainWBarDistributeB = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeB = new RebarTendonDistribute();
                    //C截面参数
                    MainLBarDistributeC = new RebarTendonDistribute(32, d1, 19);
                    AddLBarDistributeC = new RebarTendonDistribute();
                    MainWBarDistributeC = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeC = new RebarTendonDistribute();
                    break;
                case eSubType.D:
                    d1 = (Length - Radius * 2) / 19;
                    d2 = (Width - Radius * 2) / 7;
                    d1 = 80;
                    d2 = 110;
                    //spaceAlignW = d2;
                    //spaceAlignL = d1;
                    //A截面参数
                    MainLBarDistribute = new RebarTendonDistribute(32, d1, 19);
                    AddLBarDistribute = new RebarTendonDistribute();
                    AddLBarDistribute.Location = MainLBarDistribute.Delete(new List<int>() { 1,3,5,7,9,10,12,14,16,18 });
                    MainWBarDistribute = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistribute = new RebarTendonDistribute();
                    AddWBarDistribute.Location= MainWBarDistribute.Delete(new List<int>() { 2,4,6 });
                    //B截面参数
                    MainLBarDistributeB = new RebarTendonDistribute(32, d1, 19);
                    AddLBarDistributeB = new RebarTendonDistribute();
                    MainWBarDistributeB = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeB = new RebarTendonDistribute();
                    //C截面参数
                    MainLBarDistributeC = new RebarTendonDistribute(32, d1, 19);
                    AddLBarDistributeC = new RebarTendonDistribute();
                    MainWBarDistributeC = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeC = new RebarTendonDistribute();
                    break;
            }
        }

        public override void SetRebarList()
        {

            #region 0-箍筋
            int npts = GetStirrupNum();
            RebarList.Add(new MORebarRecord(1, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)MainWBarDistribute.Location[1] * -2 + 32));
            //RebarList.Add(new MORebarRecord(2, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)MainWBarDistribute.Location[3] * -2 + 32));
            int tmpn = 2;
            int tmp2 = 3;
            switch (SubType)
            {
                case eSubType.C:
                    tmpn = 2;
                    tmp2 = 3;
                    break;
                case eSubType.D:
                    tmpn = 2;
                    tmp2 = 3;
                    break;
            }
            RebarList.Add(new MORebarRecord(2, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)MainWBarDistribute.Location[tmp2] * -2 + 32));

            RebarList.Add(new MORebarRecord(3, 1, "", eDB.DB12, npts * 4, eShapeType.MO, Width - 100 - 24, MainLBarDistribute.Distance(0, tmpn) + 32));
            RebarList.Add(new MORebarRecord(3, 2, "", eDB.DB12, npts, eShapeType.MO, Width - 100 - 24, MainLBarDistribute.Distance(8, 11) + 32));
           
            RebarList.Add(new MORebarRecord(4, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, Width - 100 - 24, 138));
            #endregion

            #region 1-获取承台尺寸
            FootingBase theFooting = MemberFactory.CreatMember(MemberFactory.FromColumnToFooting(ColumnType), SubType);
            int FTHeight = theFooting.Height;
            int FTWidth = theFooting.Width;
            int FTLen = theFooting.Length;
            int db = (int)MainRebarDB;
            #endregion

            #region 2-起步筋
            int NumOFout = 0;// 外向起步筋
            int NumMainAll = MainWBarDistribute.Location.Count * 2 + MainLBarDistribute.Location.Count * 2 + 4;
            #region 正常
            if ((FTWidth - Width) * 0.5 >= 600)
            {
                NumOFout += MainLBarDistributeC.Location.Count * 2;
            }
            if ((FTLen - Length) * 0.5 >= 600)
            {
                NumOFout += MainWBarDistributeC.Location.Count * 2 + 4;
            }
            #endregion
            #region P328
            //NumOFout += MainWBarDistributeC.Location.Count * 2 + 4;; //P328;
            #endregion
            int NumAdd = AddLBarDistributeC.Location.Count * 2 + AddWBarDistributeC.Location.Count * 2;
            //5.1a为内侧起步筋，所有加强筋为内侧起步；
            string no5 = "a";
            if (NumMainAll - NumOFout + NumAdd > 0)
            {
                ////RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, true, NumMainAll - NumOFout + NumAdd, eShapeType.MHX));
                if (SubType == eSubType.C || SubType == eSubType.D)
                    RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, true, NumMainAll - NumOFout, eShapeType.MHX, 12000));
                else
                    RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, true, NumMainAll - NumOFout, eShapeType.MHX));

                no5 = "b";
            }
            //5.1b为外侧起步筋；
            if (NumOFout != 0)
            {
                if (no5 == "a")
                    no5 = "";
                ////RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, false, NumOFout, eShapeType.MHXe));
                if (SubType == eSubType.C || SubType == eSubType.D)
                    RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, false, NumOFout, eShapeType.MHXe, 12000));
                else
                    RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, false, NumOFout, eShapeType.MHXe));
            }

            #endregion



            #region 3-锚固筋

            #region 9m 45搭接
            //int Z1 = 8483 - (FTHeight - 160) - 1200; // 搭接节点 1//Z1=8483-(H-160)-1200
            #endregion
            #region 12m 45搭接
            //if (SubType == eSubType.C || SubType == eSubType.D)
            //    Z1 = 11483 - (FTHeight - 160) - 1200;
            #endregion

            #region 9/12m 250搭接
            int Z1 = 8494 - (FTHeight - 160) - 1200; // 搭接节点 1//Z1=8483-(H-160)-1200

            if (SubType == eSubType.C || SubType == eSubType.D)
                Z1 = 11494 - (FTHeight - 160) - 1200;
            #endregion

            int L2 = 0;// 盖梁锚固筋长度；
            int L12Num = 0;
            bool isDiv = false;

            int aa = (int)(1300 + LenUpper);
            if (PierHeight - Z1 + 1200 + 1500 > 12000)
            {
                // 分3节
                L12Num = NumMainAll;
                isDiv = true;
                ////L2 = (PierHeight - Z1 + 1200 + 1500 - aa);
                //L2 = (PierHeight - Z1 + 1200 - aa);
                //if (L2 + 1200 * 2 > 12000 - 45 + 32)
                //{
                //    aa += L2 + 1200 * 2 - (12000 - 45 + 32);
                //    L2 = 12000 - 45 + 32 - 2400;
                //}
                L2 = (PierHeight - Z1 + 1200 - aa);
                if (L2 + 1200 * 2 > 12000 - 250 + 248)
                {
                    aa += L2 + 1200 * 2 - (12000 - 250 + 248);
                    L2 = 12000 - 250 + 248 - 2400;
                }
            }
            else
            {
                int numA = MainWBarDistribute.Location.Count;
                // 分2节
                L2 = 1800 + (PierHeight - Z1) + 1200; // 深入盖梁钢筋总长度    
                aa = L2 - 1800;
            }

            CrossbeamBase theCB = MemberFactory.CreatMember(MemberFactory.ColumnToCrossBeam(ColumnType), 0);
            NumMainAll = MainLBarDistribute.Location.Count * 2 + MainWBarDistribute.Location.Count * 2 + 4;
            int NumL = 0;//外侧L数量

            int NumS = 0;//直线
            int bb = 0;
            int cc = 0;//1500-(B-r/2-d);
            int dd = 0;
            //int aa = L2 - 1500;         
            //if (L2 - 1500 < 0)
            //    aa = 0;
            int rr = RebarKnowledge.GerRadius(eDB.DB32);
            string no = "a";
            // 5.2a为L锚固
            // 是否与预应力冲突 ？Y:B=100
            if (Math.Abs(Length - 50 - 12 - 16 - theCB.TendonDistribute.Location[0] * -1) <= theCB.TendonDistribute.Diameter * 0.5)
            {
                // 外侧主筋L型避让
                bb = 100;
                cc = (int)(1500 - bb - rr * 0.5 - 32);
                NumL += MainWBarDistribute.Location.Count * 2 + 4;
                //RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb, cc, rr));
                //no = "b";
            }
            else
            {
                // 此时，W主筋无需避让预应力，应分析是否可以直锚？
                // 若无预应力冲突，但盖梁空间不足，B=theCB.CalculatedHeight-100
                // 外侧主筋L型避让
                bool isEixt = false;//是否在安全距离
                foreach (double item in MainLBarDistribute.Location.Values)
                {
                    //第一个对比
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)
                    {
                        isEixt = true;
                    }
                    break;

                }
                if (isEixt)//与盖梁顶部安全距离判断；
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    NumL += MainWBarDistribute.Location.Count * 2 + 4;
                    //RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb, cc, rr));
                    //no = "b";
                }
                else
                {
                    //直线布置 长度A+B
                    bb = 1500;
                    NumS += MainWBarDistribute.Location.Count * 2 + 4;
                    //RebarList.Add(new MLSRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb));                  
                    //no = "b";
                }
            }
            int NumLSZ = 0;
            ////预应力冲突 闪电避让
            //foreach (double item in MainLBarDistribute.Location.Values)
            //{
            //    foreach (double itemY in theCB.TendonDistribute.Location.Values)
            //    {
            //        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
            //            NumLSZ++;
            //    }
            //}
            int numL = 0, numS = 0; //避开预应力的主筋直线和L数量
            int NumLC = 0;//不冲突的
            int i = 0;
            Dictionary<int, string> dicDY = new Dictionary<int, string>();
            foreach (double item in MainLBarDistribute.Location.Values)
            {
                if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                {
                    bool isConflict = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {
                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    //if (!isConflict)
                    //    NumLC++;
                    //else
                    numL++;
                    dicDY.Add(i, "L");
                }
                else //安全距离之内 
                {
                    bool isSpecial = false;
                    bool isConflict = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {
                        if (itemY == 0 && item == 0)
                        {
                            isSpecial = true;
                            break;
                        }
                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    if (!isSpecial)
                    {
                        if (!isConflict)
                        {
                            numS++;
                            dicDY.Add(i, "直线");
                        }
                        else
                        {
                            dicDY.Add(i, "闪电");
                        }
                    }
                    else
                    {
                        numL++;
                        dicDY.Add(i, "L");
                    }
                }
                i++;
            }

            string mesage = "";
            foreach (int key in dicDY.Keys)
            {

                TextOper.WriteFile(key, dicDY[key], "PTM3S-"+SubType.ToString());
            }

            NumS = 12;
            //NumS += numS * 2;
            NumL = 4;
            NumLC = NumLC * 2;

            //其他
            int NumLS = NumMainAll - NumS - NumL;//闪电型         
            if (NumS > 0)
            {
                //直线锚固
                RebarList.Add(new MLSRebarRecord(5, 2, no, MainRebarDB, NumS, eShapeType.MLS, aa, 1500));
                if (no == "a")
                    no = "b";
                else if (no == "b")
                    no = "c";
                else if (no == "c")
                    no = "d";
                else if (no == "d")
                    no = "e";
                else
                    no = "f";
            }
            if (NumLS > 0)
            {
                bb = 100;
                cc = 180;
                dd = 1500 - 100 - 180;
                int numAll = 0;
                foreach (var key in dic.Keys)
                {
                    numAll += dic[key].Count * 2;
                }
                if (numAll == NumLS)
                {
                    foreach (var key in dic.Keys)
                    {
                        cc = (int)key;
                        if (cc != 3001)
                        {
                            if (cc == 200)
                            {
                                bb = 65;
                                dd = 1500 - 65 - (int)key;
                            }
                            else
                                dd = 1500 - 100 - (int)key;
                            int count = dic[key].Count * 2;
                            //闪电锚固
                            RebarList.Add(new MLZRebarRecord(5, 2, no, MainRebarDB, count, eShapeType.MLZ, aa, bb, cc, dd));
                            if (no == "a")
                                no = "b";
                            else if (no == "b")
                                no = "c";
                            else if (no == "c")
                                no = "d";
                            else if (no == "d")
                                no = "e";
                            else if (no == "e")
                                no = "f";
                            else
                                no = "g";
                        }
                        else
                        {
                            cc = 300;
                            bb = 65;                           
                            dd = 1035;
                            int ee = 1500 - bb - cc - dd + (int)(rr * 0.5) + 32;
                            int count = dic[key].Count * 2;
                            RebarList.Add(new MLSDRebarRecord(5, 2, no, MainRebarDB, count, eShapeType.MLSD, aa, bb, cc, dd, ee, rr));
                            if (no == "a")
                                no = "b";
                            else if (no == "b")
                                no = "c";
                            else if (no == "c")
                                no = "d";
                            else if (no == "d")
                                no = "e";
                            else if (no == "e")
                                no = "f";
                            else
                                no = "g";
                        }
                    }
                }
                else
                {
                    RebarList.Add(new MLZRebarRecord(5, 2, no, MainRebarDB, NumLS, eShapeType.MLZ, aa, bb, cc, dd));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else
                        no = "g";
                }

            }
            if (NumL > 0)
            {
                //L锚固

                if (NumL - NumLC > 0)
                {
                   // bb = 65;
                   // cc = 330;
                   // dd = 1035;
                   //int  ee= 1500-bb-cc-dd+(int)(rr*0.5)+32;
                   // RebarList.Add(new MLSDRebarRecord(5, 2, no, MainRebarDB, NumL - NumLC, eShapeType.MLSD, aa, bb, cc,dd,ee, rr));

                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL - NumLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else
                        no = "g";
                }
                if (NumLC > 0)
                {
                    bb = 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumLC, eShapeType.ML, aa, bb, cc, rr));
                }
            }
            if (isDiv)
            {
                RebarList.Add(new MSZRebarRecord(5, 3, "", MainRebarDB, NumMainAll, eShapeType.MSZ, L2+1200*2));
            }
            #endregion

            #region 4 加强锚固6.1
            int NumAddL = 0;//外侧L数量
            int NumAddS = 0; //直线数量
            int NumAddAll = AddWBarDistribute.Location.Count * 2 + AddLBarDistribute.Location.Count * 2;
            aa = (int)(1300 + LenUpper);
            no = "a";
            if (Math.Abs(Length - 50 - 12 - 16 - theCB.TendonDistribute.Location[0] * -1) <= theCB.TendonDistribute.Diameter * 0.5)
            {
                // 外侧主筋L型避让
                bb = 100;
                cc = (int)(1500 - bb + rr * 0.5 + 32);
                NumAddL += AddWBarDistribute.Location.Count * 2;
                //if (NumAddL > 0)
                //{
                //    RebarList.Add(new MLRebarRecord(5, 3, no, MainRebarDB, NumAddL, eShapeType.ML, aa, bb, cc, rr));
                //    no = "b";
                //}
            }
            else
            {
                // 若无预应力冲突，但盖梁空间不足，B=theCB.CalculatedHeight-100
                // 外侧主筋L型避让
                bool isEixt = false;//是否安全距离内
                foreach (double item in AddLBarDistribute.Location.Values)
                {
                    //第一个对比
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)
                    {
                        isEixt = true;
                    }
                    break;
                }
                if (isEixt)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    NumAddL += AddWBarDistribute.Location.Count * 2;

                }
                else
                {
                    //直线布置 长度A+B
                    bb = 1500;
                    NumAddL += AddWBarDistribute.Location.Count * 2;

                }
            }

            int numAddL = 0, numAddS = 0;//避开预应力的加强筋直线和L数量
            int NumAddLC = 0;//冲突
            int n = 0;
            Dictionary<int, string> dicAddDY = new Dictionary<int, string>();

            foreach (double item in AddLBarDistribute.Location.Values)
            {
                if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                {

                    bool isConflict = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {

                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    //if (!isConflict)
                    //    NumAddLC++;
                    //else
                    numAddL++;
                    dicAddDY.Add(n, "L");
                }
                else //安全距离之内 直线
                {
                    bool isConflict = false;
                    bool isSpecial = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {
                        if (itemY == 0 && item == 0)
                        {
                            isSpecial = true;
                            break;
                        }
                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    //if (isConflict)
                    //    numAddS++;
                    if (!isSpecial)
                    {
                        if (!isConflict)
                        {
                            numAddS++;
                            dicAddDY.Add(n, "直线");
                        }
                        else
                        {
                            dicAddDY.Add(n, "闪电");
                        }
                    }
                    else
                    {
                        numAddL++;
                        dicAddDY.Add(n, "L");
                    }

                }
                n++;
            }
            //numAddLL = numAddLL * 2;
            NumAddS += numAddS * 2;
            NumAddL = 4;
            NumAddLC = NumAddLC * 2;
            //其他的闪电锚固
            int NumAddLS = NumAddAll - NumAddS - NumAddL;

            if (NumAddS > 0)
            {
                RebarList.Add(new MLSRebarRecord(6, 1, no, MainRebarDB, NumAddS, eShapeType.MLS, aa, 1500));
                if (no == "a")
                    no = "b";
                else if (no == "b")
                    no = "c";
                else if (no == "c")
                    no = "d";
                else if (no == "d")
                    no = "e";
                else
                    no = "f";
            }

            if (NumAddLS > 0)
            {
                cc = 180;
                bb = 100;
                dd = 1500 - 180 - 100;
                int numAll = 0;
                foreach (var key in addDic.Keys)
                {
                    numAll += addDic[key].Count * 2;
                }
                if (numAll == NumAddLS)
                {
                    foreach (var key in addDic.Keys)
                    {
                        cc = (int)key;
                        if(cc==185)
                        {
                            bb = 65;
                            dd = 1500 - bb - (int)key;
                        }
                        else
                           dd = 1500 - 100 - (int)key;
                        int count = addDic[key].Count * 2;
                        //闪电锚固
                        RebarList.Add(new MLZRebarRecord(6, 1, no, MainRebarDB, count, eShapeType.MLZ, aa, bb, cc, dd));
                        if (no == "a")
                            no = "b";
                        else if (no == "b")
                            no = "c";
                        else if (no == "c")
                            no = "d";
                        else if (no == "d")
                            no = "e";
                        else
                            no = "f";
                    }
                }
                else
                {
                    RebarList.Add(new MLZRebarRecord(6, 1, no, MainRebarDB, NumAddLS, eShapeType.MLZ, aa, bb, cc, dd));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else
                        no = "f";
                }
            }
            if (NumAddL > 0)
            {

                if (NumAddL - NumAddLC > 0)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(6, 1, no, MainRebarDB, NumAddL - NumAddLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else
                        no = "f";
                }
                if (NumAddLC > 0)
                {

                    bb = 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);

                    RebarList.Add(new MLRebarRecord(6, 1, no, MainRebarDB, NumAddLC, eShapeType.ML, aa, bb, cc, rr));
                }
            }
            #endregion

            #region UBlot数量计算
            if (isDiv)
                UAN1N2 = NumMainAll * 8;
            else
                UAN1N2 = NumMainAll * 4;
            if (isDiv)
            {
                UboltList.UBoltNum[MainRebarDB] += NumMainAll * 8;
            }
            else
            {
                UboltList.UBoltNum[MainRebarDB] += NumMainAll * 4;
            }
            #endregion
        }


        void Test()
        {
            
            ECrossBeamType CBtype = MemberFactory.ColumnToCrossBeam(ColumnType);
            CrossbeamBase CB= MemberFactory.CreatMember(CBtype, 30000);

            RebarCollection TypeL = new RebarCollection();
            RebarCollection TypeI = new RebarCollection();
            RebarCollection TypeZ = new RebarCollection(); // L避让，不避让，Z型避让

            //判断顺桥向两排主筋
            if ((Math.Abs(CB.TendonDistribute.Location[0])-(Length*0.5-50-12-32*0.5))<0.5*CB.TendonDistribute.Diameter)
            {
                TypeL.Add(new MLRebarRecord(5, 2, "b", eDB.DB32, MainWBarDistribute.Location.Count * 2, eShapeType.ML, 1, 2, 3, RebarKnowledge.GerRadius(eDB.DB32)));

            }

            var test = 1;
        }


    }

}
